Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type annotation update pre commit #122

Conversation

bernhardkaindl
Copy link
Collaborator

@bernhardkaindl bernhardkaindl commented Jan 18, 2024

Hello @psafont and @GeraldEV!

If you believe it would be better for your review to split this PR into smaller PRs, I can do so of course!

But as the changes to the xcp/ package itself are minimal, I think it is safe to review as is:

  • in xcp/ there is only removal of 3 unused except Exception as e: variables, which can be seen from the diff review.

Background info:

I was reviewing the Python3 changes for the host-upgrade-plugin that have to be reverted because they were totally broken (the manual test didn't execute the code properly).

When running pytype and pyright (or just open it in an IDE like VS code which uses pyright for it's Python3 checking and type derivation) on the host-upgrade-plugin, you'll immediately see that the Python3 commit that was done was never run on Python (Python2 and not Python3) interpreter.

pytype was able to find many real bugs (some we noticed and had to revert in xen-api) in xapi-project/xen-api#5365

I saw that it uses the xcp python-libs extensively, especially the more involved Bootloader and Accessor modules.

Description of the Changes:

I saw that I had previously problems arriving at and adding the correct type comment for xcp.acccessor.createAccessor().

  • With more experience, I now integrate the correct type annotation!
  • The added type annotation also requires improvements to the typing in the unit tests!
  • All static checkers (mypy, pytype, pyre) as well as pylint are fixed to work with it now!

While at it, document the API of ctypes fully xcp.acccessor.createAccessor() in a new docstring to not have to re-collect all that information once again in the future.

Some interfaces of Pylint changed with the current version of pylint, so I also needed some changes to work with.

Fix the remaining pylint warnings for unused variables and script/module names without dashes/hyphens.

Fix the CI runner scripts accordingly.

Fix the remaining unclosed file handling in a test where a StringIO was not closed in the correct order which caused a few warnings from the enabled PYTHONDEVMODE checks.

The main commit for the xcp is to add the type comment and the docstring:

The rest are just cleanups.

The changes in this commit don't change the user's API,
only cleanup and disable comments would change the user's API:

- Rename the CI scrpts with accordingy and
- Rename the non-default pylintrc to .pylintrc.
- Update CI config to work with newer versions of pylint

Signed-off-by: Bernhard Kaindl <[email protected]>
Copy link

codecov bot commented Jan 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (080bfd9) 83.23% compared to head (dc15c5e) 83.25%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #122      +/-   ##
==========================================
+ Coverage   83.23%   83.25%   +0.01%     
==========================================
  Files          22       22              
  Lines        3359     3363       +4     
==========================================
+ Hits         2796     2800       +4     
  Misses        563      563              
Flag Coverage Δ
unittest 83.25% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bernhardkaindl bernhardkaindl merged commit feeb478 into xenserver:master Jan 30, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants